import Vue from 'vue'
import Router from 'vue-router'
import { activityRouter } from './children/activity.js'
import { adRouter } from './children/advertisement.js'
import { couponRouter } from './children/coupon.js'
import { privateRouter } from './children/privatePlacementList.js'
import { creditorRouter } from './children/creditor.js'
import { transRouter } from './children/transactionManagement.js'
import { webArticle } from './children/webArticle.js'
import noticeRouter from './children/noticeManage.js'
import { SystemManagement } from './children/SystemManagement.js'
import { user } from './children/user.js'
import { cooperationPlatform } from './children/cooperationPlatform.js'
import Home from 'components/Hello'
Vue.use(Router);
const router = new Router({
    base: '/eurus/',
    routes: [{
            path: '/login',
            name: 'login',
            component: resolve => require(['views/login/Login'], resolve),
            hidden: true
        },
        {
            path: '/chgPassword', //修改密码
            name: 'chgPassword',
            component: resolve => require(['views/login/ChangePassword'], resolve),
            hidden: true
        },
        {
            path: '/notFound',
            name: 'notFound',
            component: resolve => require(['components/404'], resolve),
            hidden: true
        },
        {
            path: '/',
            component: Home,
            // name: 'home',
            hidden: true,
            children: [{
                    path: '',
                    name: 'hello',
                    component: resolve => require(['views/hello/index.vue'], resolve)
                },
                {
                    path: '',
                    name: '活动管理',
                    component: resolve => require(['components/contentBox/index.vue'], resolve),
                    children: activityRouter
                },
                {
                    path: '',
                    name: '私募',
                    component: resolve => require(['components/contentBox/index.vue'], resolve),
                    children: privateRouter
                },
                {
                    path: '',
                    name: '卡券',
                    component: resolve => require(['components/contentBox/index.vue'], resolve),
                    children: couponRouter
                },
                {
                    path: '',
                    name: '广告',
                    component: resolve => require(['components/contentBox/index.vue'], resolve),
                    children: adRouter
                },
                {
                    path: '',
                    name: '债权人',
                    component: resolve => require(['components/contentBox/index.vue'], resolve),
                    children: creditorRouter
                },
                {
                    path: '',
                    name: '系统管理',
                    component: resolve => require(['components/contentBox/index.vue'], resolve),
                    children: SystemManagement,
                    hidden: false
                },
                {
                    path: '',
                    name: '用户管理',
                    component: resolve => require(['components/contentBox/index.vue'], resolve),
                    children: user,
                    hidden: false
                },
                {
                    path: '',
                    name: '交易管理',
                    component: resolve => require(['components/contentBox/index.vue'], resolve),
                    children: transRouter
                },
                {
                    path: '',
                    name: '公告管理',
                    component: resolve => require(['components/contentBox/index.vue'], resolve),
                    children: noticeRouter
                },
                {
                    path: '',
                    name: '官网内容管理',
                    component: resolve => require(['components/contentBox/index.vue'], resolve),
                    children: webArticle
                },
                {
                    path: '',
                    name: '合作管理',
                    component: resolve => require(['components/contentBox/index.vue'], resolve),
                    children: cooperationPlatform
                }
            ]
        },
        {
            path: '*',
            redirect: { path: '/notFound' },
            hidden: true
        }
    ]
});
router.beforeEach((to, from, next) => {
    // console.log(`router_page : ${sessionStorage.getItem('router_page')}`, '即将前往=>', to)
    let user = JSON.parse(sessionStorage.getItem('HKid'));
    if (!user && to.path !== '/login') {
        next({ path: '/login' })
    } else {
        sessionStorage.setItem('router_page', to.name)
        next()
    }
});
export default router